package com.javasm.controller;

import com.javasm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @author: Lisa
 * @className: TestController
 * @description:
 * @date: 2023/10/21 19:04
 * @VERSION: 0.1
 * @SINCE: jdk11
 */
@RestController
public class TestController {
    @Autowired
    private UserService userService;
    @Autowired
    private JavaMailSender javaMailSender;

    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("sendMail")
    public String sendMail(String email){
        System.out.println(email);
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        mailMessage.setTo(email);
        mailMessage.setFrom("2969886198@qq.com");
        mailMessage.setSubject("验证码");
        String code = UUID.randomUUID().toString().substring(0, 6);
        mailMessage.setText("验证码是："+code);
        javaMailSender.send(mailMessage);
        redisTemplate.opsForValue().set(email,code);
        return "success";
    }

    @GetMapping("success")
    public String success(){
        System.out.println("success");
        return "success";
    }


}
